using System.Collections.Immutable;
using DimensionsHelper.LanguageService.Symbols;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public class AnalysisBoolean : AnalysisExpression
{
    internal AnalysisBoolean(BooleanLiteral source, AnalysisNode? parent) :
        base(AnalysisBoundKinds.Literal, source, parent)
    {
        Syntax = source;
        Value = source.Value;
        Bind(ValueTypeSymbol.Boolean);
    }


    public override BooleanLiteral Syntax { get; }


    /// <summary>
    ///     布尔常量值
    /// </summary>
    public bool Value { get; }


    public override AnalysisExpression? WithImplicitlyConversion(ValueTypeSymbol targetType)
    {
        if (targetType == ValueTypeSymbol.Boolean || targetType == ValueTypeSymbol.Any)
        {
            return this;
        }

        return null;
    }


    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return ImmutableArray<AnalysisNode>.Empty;
    }

    internal override void AddChild(AnalysisNode child)
    {
        throw new NotSupportedException("AnalysisBoolean cannot have children.");
    }
}


public static partial class AnalysisNodeFactory
{
    /// <summary>
    /// 创建一个布尔常量表达式
    /// </summary>
    /// <param name="syntaxNode">原始语法节点</param>
    /// <param name="parent">父节点</param>
    public static AnalysisBoolean Boolean(BooleanLiteral syntaxNode, AnalysisNode? parent)
    {
        return new AnalysisBoolean(syntaxNode, parent);
    }
}